import { Controller, UseGuards, UsePipes } from '@nestjs/common';
import { Crud }  from 'nestjs-mongoose-crud'
import { Commodity } from '@lib/db/models/commodity.model';
import { ApiUseTags, ApiBearerAuth } from '@nestjs/swagger';
import { InjectModel } from 'nestjs-typegoose';
import { ModelType } from '@typegoose/typegoose/lib/types';
import { NullArrayToNull } from './nullarray-null.pipe';
import { AuthGuard } from '@nestjs/passport';

@Crud({
  model: Commodity,
  routes: {
    find: {
      populate: ['category', 'services', 'comments']
    }
  }
})
@Controller('commodities')
@ApiUseTags('商品管理')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
@UsePipes(new NullArrayToNull(['services']))
export class CommoditiesController {
  @InjectModel(Commodity) private readonly model: ModelType<Commodity>
}
